library(foreign)
library(pander)

representativeness.function.gotv <- function(experiment.df, vars) {
  data <- experiment.df
  representativeness.vars <- vars
  x.assigned <- data[,representativeness.vars]
  x.assigned <- as.matrix(x.assigned, dimnames = list(NULL, names(x)))
  x.attempted <- subset(data, data$attempted == 1, representativeness.vars) #Create data of attempted respondents.
  x.attempted <- as.matrix(x.attempted, dimnames = list(NULL, names(x)))
  x.canvassed <- subset(data, data$canvassed == 1, representativeness.vars) #Create data of canvassed respondents.
  x.canvassed <- as.matrix(x.canvassed, dimnames = list(NULL, names(x)))
  assigned.means <- data.frame(t(colMeans(x.assigned))) #Calculate means.
  assigned.means$n <- nrow(x.assigned)
  attempted.means <- data.frame(t(colMeans(x.attempted)))
  attempted.means$n <- nrow(x.attempted)
  canvassed.means <- data.frame(t(colMeans(x.canvassed))) #Calculate means.
  canvassed.means$n <- nrow(x.canvassed)
  means <- rbind(assigned.means, attempted.means, canvassed.means)
  row.names(means) <- c("Starting Universe", "Attempted", "Canvassed")
  means <- t(means)
  #Print
  panderOptions('big.mark', ',')
  panderOptions('table.style','rmarkdown')
  panderOptions('table.alignment.default','right')
  panderOptions('table.alignment.rownames','left')
  panderOptions('digits','2')
  panderOptions('table.caption.prefix','')
  set.caption("**Representativeness of Experiment at Each Stage.** Each cell reports the average value of a different covariate at each stage.")
  pander(means, split.tables = 110)
}